unit cuZoom;

interface

type
  TZoom = class( TObject )
  public
    Value,
    Step,
    ZoomMax,
    ZoomMin,
    ZoomGoto : real;

    constructor Create();
    procedure setZoom(nValue,nStep,nMin,nMax:real);
    procedure zoomIn();
    procedure zoomOut();
    procedure zoomAuto();
  end;

implementation

uses SysUtils, Math;

constructor TZoom.Create();
begin
   SetZoom( 0.2, 1, -20, 200);
end;

procedure TZoom.setZoom(nValue,nStep,nMin,nMax:real);
begin
  Value    := nValue;
  Step     := nStep;
  ZoomMin  := nMin;
  ZoomMax  := nMax;
  ZoomGoto := -1;
end;

procedure TZoom.zoomIn();
begin
//  Value := (Value * Step) + Value;
  Value := Value + (Value * Step);

  if (Value > ZoomMax) then Value := ZoomMax;
end;

procedure TZoom.zoomOut();
begin
  Value := Value - (Value * Step);

  if (Value < ZoomMin) then Value := ZoomMin;
end;

procedure TZoom.zoomAuto();
begin
  if (ZoomGoto <> -1) then
  begin
    if (ZoomGoto > Value)  then
      ZoomIn()
    else
      ZoomOut();

    if (Value - ZoomGoto < Step) then
      Value := ZoomGoto;
  end;
end;

end.
